package com.sky.wsp.rabbitmq.producer;

import com.sky.wsp.rabbitmq.exchange.DirectExchangeConfig;
import com.sky.wsp.rabbitmq.exchange.FanoutExchangeConfig;
import com.sky.wsp.rabbitmq.exchange.TopicExchangeConfig;
import com.sky.wsp.rabbitmq.po.MqMessage;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class MqProducer {
    @Autowired
    RabbitTemplate rabbitTemplate;

    /**
     * 使用fanout交换机发布消息给所有队列
     */
    public void sendFanout(MqMessage msg) {
        rabbitTemplate.convertAndSend(FanoutExchangeConfig.EXCHANGE_NAME, null, msg);
    }

    /**
     * 使用direct交换机发送消息
     */
    public void senddirectMail(String routingKey, MqMessage msg) {
        rabbitTemplate.convertAndSend(DirectExchangeConfig.EXCHANGE_NAME, routingKey, msg);
    }

    /**
     * 使用topic交换机发送消息
     */
    public void sendtopicMail(String routingKey, MqMessage msg) {
        rabbitTemplate.convertAndSend(TopicExchangeConfig.EXCHANGE_NAME, routingKey, msg);
    }
}
